<?php

include 'DBconn.php';

class CountryMaster {

    public function getAllCountries() {
        $result = mysql_query("select * from country_header where activestatus=1") or die(mysql_error());
        $res_arr = array();
        while ($row = mysql_fetch_object($result)) {
            $tmp = new VOCountryMaster();
            $tmp->serialnumber = (int) $row->serialnumber;
            $tmp->country_name = $row->country_name;
            $tmp->cre_userid_fk = (int) $row->cre_userid_fk;
            $tmp->cre_datetime = $row->cre_datetime;
            $tmp->activestatus = (boolean) $row->activestatus;
            $res_arr[] = $tmp;
        }
        mysql_free_result($result);
        return $res_arr;
    }

    public function getCountriesNotHaveCurrency() {
        $result = mysql_query("select * from country_header where country_name Not In (select currency_country From currency_header) and activestatus=1") or die(mysql_error());
        $res_arr = array();
        while ($row = mysql_fetch_object($result)) {
            $tmp = new VOCountryMaster();
            $tmp->serialnumber = (int) $row->serialnumber;
            $tmp->country_name = $row->country_name;
            $tmp->cre_userid_fk = (int) $row->cre_userid_fk;
            $tmp->cre_datetime = $row->cre_datetime;
            $tmp->activestatus = (boolean) $row->activestatus;
            $res_arr[] = $tmp;
        }
        mysql_free_result($result);
        return $res_arr;
    }

    public function addNewCountry($VObject) {
        $country_name = ucfirst($VObject->country_name);
        $query = "insert into country_header(country_name,cre_userid_fk,cre_datetime,activestatus)values('$country_name','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
        $s = mysql_query($query) or die(mysql_error());
        return $this->getAllCountries();
    }

    public function deleteCountry($serialnumber) {
        $query = "update country_header set activestatus=0 where serialnumber='$serialnumber'";
        $s = mysql_query($query) or die(mysql_error());
        return $serialnumber;
    }

    public function editCountry($VObject) {
        $country_name = ucfirst($VObject->country_name);
        $query = "update country_header set country_name='$country_name' where serialnumber=" . $VObject->serialnumber;
        $s = mysql_query($query) or die(mysql_error());
        return $this->getAllCountries();
    }

}

class VOCountryMaster {
    var $serialnumber;
    var $country_name;
    var $cre_userid_fk;
    var $cre_datetime;
    var $activestatus;
}

?>